<extend name="base" />
<block name="CONTENT">
    <!--开始 授权-->
    <div class="contextMargin">
        <div class="col-sm-12 contextBotton marginBottom30">
            <div class="color9 size14">当前位置：账户设置>Amazon设置</div>
        </div>
        <div class="col-sm-12 contextTop contextBaground ">
            <div class="userPadding">
                <div class="userHeader">
                    <i></i>亚马逊授权，以便数据同步
                    <a href="{:U('Home/Index/authorizeHelp')}" target="_blank" class="operate">授权帮助</a>
                </div>
                <div class="userboder"></div>
                <div class="col-xs-12 col-sm-12 col-md-5 shopleft0 shopright0">
                    <div class="col-xs-12 labeiTop20 color3 size16 shopleft0 shopright0">新增店铺(每次仅允许添加一个系列的站点)：</div>
                    <div class="col-xs-12 userboders"></div>
                    <div class="col-xs-12 labeiTop20 color6">
                        <div class="col-xs-2 shopright0 text-right labeiTop6">亚马逊站点：</div>
                        <div class="col-xs-10">
                            <div class="authorizeTable shopTables">
                                <ul class="authorize-tabs">
                                    <li class="active" data-cty="1">美系</li>
                                    <li data-cty="2">欧洲</li>
                                    <li data-cty="3">日系</li>
                                </ul>
                            </div>

                            <div class="shopAuthorize1 clearfix">
                                <volist name="amazonMarketsInfo" id="vo">
                                    <if condition="$vo.MarketType eq 1">
                                        <div class="checkbox size14 laomarginTop5 shopFloat marginBottom20 countryIndex">
                                            <div class="checkGroup position size14 authorizeBtnClick" data-tab="{$vo.ID}">
                                                <span class="color6" style="margin-left:20px;">{$vo.MarketCNName}</span>
                                                <i class="checkLogo"></i>
                                            </div>
                                        </div>
                                    </if>
                                </volist>
                            </div>

                            <div class="shopAuthorize2 clearfix">
                                <volist name="amazonMarketsInfo" id="vo">
                                    <if condition="$vo.MarketType eq 2">
                                        <div class="checkbox size14 laomarginTop5 shopFloat marginBottom20 countryIndex">
                                            <div class="checkGroup position size14 authorizeBtnClick" data-tab="{$vo.ID}">
                                                <span class="color6" style="margin-left:20px;">{$vo.MarketCNName}</span>
                                                <i class="checkLogo"></i>
                                            </div>
                                        </div>
                                    </if>
                                </volist>
                            </div>

                            <div class="shopAuthorize3 clearfix">
                                <volist name="amazonMarketsInfo" id="vo">
                                    <if condition="$vo.MarketType eq 3">
                                        <div class="checkbox size14 laomarginTop5 shopFloat marginBottom20 countryIndex">
                                            <div class="checkGroup position size14 authorizeBtnClick" data-tab="{$vo.ID}">
                                                <span class="color6" style="margin-left:20px;">{$vo.MarketCNName}</span>
                                                <i class="checkLogo"></i>
                                            </div>
                                        </div>
                                    </if>
                                </volist>
                            </div>

                        </div>
                    </div>
                    <div class="col-xs-12 labeiTop20 color6">
                        <div class="col-xs-2 shopright0 text-right labeiTop6">Seller ID：</div>
                        <div class="col-xs-10">
                            <input id="inputStyle" name='SellerID' class="col-xs-12" type="text" />
                        </div>
                    </div>
                    <div class="col-xs-12 labeiTop20 color6">
                        <div class="col-xs-2 shopright0 text-right labeiTop6">Auth Token：</div>
                        <div class="col-xs-10">
                            <input id="inputStyle" name='AuthToken' class="col-xs-12" type="text" />
                        </div>
                    </div>
                    <div class="col-xs-12 labeiTop20 labeiPaddingButton20">
                        <div class="col-xs-2"></div>
                        <div class="col-xs-10">
                            <div class="authorizeBtn">确定</div>
                        </div>
                    </div>
                </div>
                <div class="col-xs-0 col-md-2 col-sm-0"></div>
                <div class="col-xs-12 col-sm-12 col-md-5 shopleft0 shopright0">
                    <div class="col-xs-12 labeiTop20 shopleft0 shopright0">
                        <div class="col-xs-6 color3 size16 shopleft0 shopright0">已授权的店铺：</div>
                        <div class="col-xs-6 shopleft0 shopright0 text-right color9">我们承诺会严格保密您的信息</div>
                    </div>
                    <div class="col-xs-12 userboders"></div>
                    <div class="col-xs-12 contextTop shopleft0 shopright0 labeiTop20">
                        <table class="table table-striped table-bordered table-hover" style="margin-bottom: 0px;">
                            <thead>
                            <tr class="tableStyle size14">
                                <th>店铺名称</th>
                                <th>站点</th>
                                <th>操作</th>
                            </tr>
                            </thead>

                            <tbody class="contrast shopCont">
                            <volist name="marketsList" id="vo">
                                <tr class="trColor">
                                    <td>{$vo.UserMarketCNName}</td>
                                    <td>{$vo.MarketCNName}</td>
                                    <td>
                                        <a href="javascript:void(0);" class="ctOperate updateAmazonauthShow" recordid="{$vo.ID}" isactive="{$vo['isActive']==1?0:1}"  usermarketcnname="{$vo.UserMarketCNName}"><i class="ace-icon fa {$vo['isActive']==1?'fa-eye':'fa-eye-slash'} bigger-130 deleteB"></i></a>
                                        <a href="javascript:void(0);" class="ctOpxerate deleteAmazonauth" recordid="{$vo.ID}" marketid="{$vo.MarketID}"><i class="ace-icon fa fa-trash-o bigger-130 deleteB"></i></a>
                                        <a href="javascript:void(0);" class="ctOperate"><i class="ace-icon fa fa-refresh bigger-130 deleteB"></i></a>
                                        <a href="#" class="ctOperate updateAmazonauthCNName" data-toggle="modal" data-target="#updataModal" class="updateAmazonauthCNName" recordid="{$vo.ID}" usermarketcnname="{$vo.UserMarketCNName}" isactive="{$vo.isActive}"><i class="ace-icon fa fa-pencil bigger-130 deleteB"></i></a>
                                    </td>
                                </tr>
                            </volist>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--结束 授权-->
    <!--开始 修改 店铺 名称-->
    <div class="modal fade" id="updataModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">编辑</h4>
                </div>
                <div class="modal-body" style="padding: 30px 0 !important;">
                    <div class="text-center">
                        <label class="control-label no-padding-right labeichage" for="form-field-1">店铺名称:</label>
                        <input type="hidden" id="IsActive" />
                        <input type="hidden" id="CNNRecordID" />
                        <input id="inputStyle" class="inputStyle modalValue UserMarketCNNames" type="text" placeholder="" value=""/>
                    </div>
                </div>
                <div class="modal-footer">
                    <div class="updateBtnright modalFloat" data-dismiss="modal" id="updateMarketCNname">确定</div>
                </div>
            </div>
        </div>
    </div>
    <!--结束 修改 店铺 名称-->
</block>
<!-- 开始 页面 级 代码 -->
<block name="JAVASCRIPT_PAGE_LEVEL_CODE">
    <script>
        $(function(){
            /**
             * 新增店铺 操作
             * @author xiaojing
             */
            $('.authorizeBtn').on('click',function(){
                var data  = new Array();
                var UserSellerID_value = $("input[name='SellerID']").val();
                var UserAuthToken_value = $("input[name='AuthToken']").val();

                // 获取勾 选 国家 和店铺名称
                $.each($('.removeInputDiv'),function(i,oj){
                    var UserMarketCNName_value =  $(oj).find('.UserMarketCNName').val();
                    var MarketID_value = $(oj).find('.MarketID').val();
                    data[i] =  {UserMarketCNName_value:UserMarketCNName_value,MarketID_value:MarketID_value};
                });

                data =  JSON.stringify(data);

                $.post('index.php?s=/home/index/saveamazonauth',
                        {
                            data:data,
                            UserSellerID_value:UserSellerID_value,
                            UserAuthToken_value:UserAuthToken_value
                        },function(res){
                            medal.init({msg:'操作成功',type:'success',callback:function(){
                                window.location.href  = '/index.php?s=/home/index/amazonauthmarkest';
                            }});
                        });
            });

            /**
             * 隐藏显示 店铺 数据
             *  @author xiaojing
             */
            $('.updateAmazonauthShow').on('click',function(){
                var data  = {};
                data.RecordID = $(this).attr('recordid');
                data.IsActive = $(this).attr('isactive');
                data.UserMarketCNName = $(this).attr('usermarketcnname');
                $.post('index.php?s=/home/index/updateamazonauth',data,
                        function(res){
                            medal.init({msg:'操作成功',type:'success',callback:function(){
                                window.location.href  = '/index.php?s=/home/index/amazonauthmarkest';
                            }});
                        },'JSON')
            });

            /**
             * 修改 店铺 名称 展示
             * @author xiaojng
             */
            $('.updateAmazonauthCNName').on('click',function(){
                $('#CNNRecordID').val($(this).attr('recordid'));
                $('#IsActive').val($(this).attr('isactive'))
                $('.UserMarketCNNames').val($(this).attr('usermarketcnname'));
            });

            /**
             * 修改 店铺 名称 保存
             * @author xiaojing
             */
            $('#updateMarketCNname').on('click',function(){
                var data  = {};
                data.RecordID = $('#CNNRecordID').val();
                data.UserMarketCNName = $('.UserMarketCNNames').val();
                data.IsActive = $('.IsActive').val();
                $.post('index.php?s=/home/index/updateamazonauth',data,
                    function(res){
                        medal.init({msg:'操作成功',type:'success',callback:function(){
                            window.location.href  = '/index.php?s=/home/index/amazonauthmarkest';
                        }});
                    },'JSON');
            });

            /**
             * 删除 店铺
             * @author xiaojing
             */
            $('.deleteAmazonauth').on('click',function(){
                /*medal.init({

                    msg:'确认要执行此操作吗？',

                    type:'warning',

                    callback:function(){

                        var data  = {};

                        data.RecordID = $(this).attr('recordid');

                        data.MarketID = $(this).attr('marketid');

                        $.post('index.php?s=/home/index/deleteamazonauth',data,
                        	function(res){medal.init({msg:'操作成功',type:'success',function(){
                                window.location.href  = '/index.php?s=/home/index/amazonauthmarkest';
                            }});
                        	},'JSON');
                    }
                });*/
            });
        })
    </script>
</block>
<!-- 结束 页面 级 代码 -->